package com.example.testlibraryproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;

import com.example.testlibraryproject.callbacks.OnItemSwipeCallback;
import com.example.testlibraryproject.helpers.SwipeGestureListener;
import com.example.testlibraryproject.utils.L;

public class MainGestureTest extends Activity implements OnItemSwipeCallback {
	/**
	 * 1)Create gesture listener to handled swipe events
	 * 2)IMplement gesture listener on item swipeCallback,
	 * 3)Initailize gestureDetector with gesture listener.
	 * 4)override dispatchTouchEvent for call gesturedetector.onTouch, 
	 * if not handled call super method for dispathTouchEvent
	 */
	
	//for gesture events
	GestureDetector swipeGestureDetector;
	SwipeGestureListener swipeGestureListener;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gesture_test);
		
		
		//for swipe events
		swipeGestureListener = new SwipeGestureListener(this);
		// set the OnItemSwipeListener which implements abstract method onItemSwipe
		swipeGestureListener.setOnItemSwipeListener(this);
		swipeGestureDetector = new GestureDetector(this, swipeGestureListener);
		//end for swipe events
	}
	
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		boolean handled = swipeGestureDetector.onTouchEvent(ev);

		//handling if touch not handled
		if(!handled){
			handled = super.dispatchTouchEvent(ev);
		}
		return handled;
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main_gesture_test, menu);
		return true;
	}

	public void onTempBtnClik(View v){
		L.v("Button clicked");
	}

	@Override
	public void onItemSwipe(int swipeType) {
		// TODO Auto-generated method stub
		
		switch (swipeType) {

		case SwipeGestureListener.SWIPE_TYPE_LEFT:
			L.v("swiped left");
			//TODO 
			break;

		case SwipeGestureListener.SWIPE_TYPE_RIGHT:
			L.v("swiped right");
			//TODO
			break;
			
		case SwipeGestureListener.SWIPE_TYPE_TOP:
			L.v("swiped top");
			//TODO 
			break;

		case SwipeGestureListener.SWIPE_TYPE_BOTTOM:
			L.v("swiped bottom");
			//TODO
			break;
			

		default:
			break;
		}
		
	}

}
